package L1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _094 {
    /**
     * 剪切粘贴
     */
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        int N = Integer.valueOf(reader.readLine());
        for (int i=0;i<N;i++){
            String[] s = reader.readLine().split(" ");
            int start = Integer.valueOf(s[0])-1;
            int end = Integer.valueOf(s[1]);
            String temp = line.substring(start,end);
            line=line.substring(0,start)+line.substring(end);
            int index = line.indexOf(s[2] + s[3]);
            if (index!=-1){
                line=line.substring(0,index+s[2].length())+temp+line.substring(index+s[2].length());
            }else{
                line+=temp;
            }
        }
        System.out.println(line);
    }
}
